﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using SysFrame.BP;
using SysFrame.Message;

namespace AppServer.Controllers.System
{
    [Route("api/[controller]")]
    [ApiController]
    public class System5Controller : SysControllerBase
    {
        //字典
        // POST: api/System6
        [HttpPost]
        public ActionResult<string> Post([FromBody] dynamic data)
        {
            string jsTimeStamp = data.jsTimeStamp;
            string Action = data.Action == null ? "Get" : data.Action;
            string rtstr = "";
            if (Action == "Get")
            {
                rtstr = Get(data);
            }
            if (Action == "Save")
            {
                rtstr = Save(data);
            }
            return rtstr;
        }

        /// <summary>
        /// 得到字典
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public string Get(dynamic data)
        {
            //分类id
            JObject postdata = JObject.FromObject(data.data);
            string search = postdata["search"].ToString();
            MsQuery ms = new MsQuery();
            Mssystem_1 lodeuser = GetSessionUser();
            //条件 不是管理员
            if (!lodeuser.isadmin)
            {
                ms.strquery += " and (SYSTEM_5_60='1' or SYSTEM_5_60 is Null )";
            }
            if (!string.IsNullOrEmpty(search)) {
                ms.strquery += " and (SYSTEM_5_20 like '%" + search + "%' or SYSTEM_5_30 like '%" + search + "%' or SYSTEM_5_40 like '%" + search + "%')";
            }
            //ms.strorder = "  ";//排序语句
            List<Mssystem_5> listms = new BLLsystem_5().Getsystem_5MsByQuery(ms);
            return JArray.FromObject(listms).ToString();

        }

        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public string Save(dynamic data)
        {
            JObject postdata = JObject.FromObject(data.data);
            Mssystem_5 ms = Mssystem_5.parse<Mssystem_5>(postdata);
            //ms8.System_8_50 = "1";
            MsReturned rt = new BLLsystem_5().Savesystem_5(ms);
            return JObject.FromObject(rt).ToString();
        }
    }
}